/**
 * 
 */
package neptune.manager.validator.rules.topology;

import neptune.manager.model.topology.Node;
import neptune.manager.model.topology.Topology;
import neptune.manager.utils.Logger.MessageType;
import neptune.manager.validator.ValidatorResult;
import neptune.manager.validator.ValidatorRule;
import neptune.manager.validator.Validator.Status;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 *
 */
public class TopologyNodesUniquenessRule extends ValidatorRule<Topology> {

	@Override
	public String getName() {
		return "TopologyNodesUniquenessRule";
	}

	@Override
	protected ValidatorResult validationAlgorithm(Topology toValidate,
			ValidatorResult result) {
		
		for (Node node : toValidate.getNodes()) {
			int idNumberOfOccurencies = 0;
			for (Node comparedNode : toValidate.getNodes()) {
				if(comparedNode.getId().equals(node.getId()))
					idNumberOfOccurencies++;
			}
			if(idNumberOfOccurencies != 1){
				result.setStatus(Status.ERROR);
				result.getLog().addMessage("Number of occurencies for id '"
						+ node.getId() + "' is not 1 but "
						+ idNumberOfOccurencies, MessageType.ERROR);
			}
		}
		
		
		return null;
	}

}
